Skip to content

default background and foreground for inline code in dark mode #13182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 18, 2025

Conversation

gordonwoodhull
Copy link
Contributor

@gordonwoodhull gordonwoodhull commented Aug 4, 2025

Default inline code background color, both with and with and without sourceCode, to the block background color and not $grey-100

Before After
image image
image image
image image

Fixes #8568

It leaves the inline code foreground color defaulted to purple in light mode, which seems to be intentional. In dark mode, it uses $pre-color which exists in that mode.

I think the fix is correct and safe but it may be more convoluted than we want.

The problem is, $code-bg, which controls the inline code background color, has a bad default for dark mode of $gray-100 (in _bootstrap-variables.scss) but the way to calculate the correct color for dark mode is not known until _bootstrap-rules.scss.

I couldn't !default it, or set it outright, so Claude suggested this kludge of checking if $code-bg has its default setting. 😛

I have tested this manually

  • with light dark flatly/darkly and cosmo/solar
    • both with and without brand.typography.monospace-inline.background-color (which is the current workaround for the original bug).
  • with no theme
    • with and without brand
      No warnings.

Includes playwright tests for a11y and arrow themes.

Visual design considerations

This is the minimal change, but

  • As shown in the after screenshot, visually the inline code background appears darker than the code block background, because it's smaller. So perhaps it should be lighter!
  • There is no reason not to choose a more interesting default color for the dark mode foreground color for inline code, especially as our default in light mode is purple. (Surfing git blame, it took a while to settle on this color.)

@posit-snyk-bot
Copy link
Collaborator

posit-snyk-bot commented Aug 4, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@gordonwoodhull
Copy link
Contributor Author

gordonwoodhull commented Aug 14, 2025

This gets more complicated when you consider inline code with .sourceCode e.g.

Inline code: `identity <- function(x) x`{.r}

In this case, we are getting the background and foreground colors straight from bootstrap

code {
  font-size: 0.875em;
  color: var(--bs-code-color);
  background-color: #f8f9fa;
  border-radius: .375rem;
  padding: .125rem .25rem;
  word-wrap: break-word;
}

and we don't have any rules for code.sourceCode only :not(.sourceCode).

It's easy enough to add a rule for inline code with .sourceCode

p code.sourceCode,
li code.sourceCode,
td code.sourceCode {
  // same as code:not(.sourceCode) but without unrelated padding stuff
}

I don't find the default foreground color var(--bs-code-color) to be satisfactory in any of

  • cosmo + stylesheet (dark gray inherit, darker than syntax highlighting1)
  • solar, slate (a different bootstrap code color from our default, rgb(192, 128, 216))

We don't mention bs-code-color anywhere; my attempts to override it failed.

Granted, it's better than not doing anything, see "before" image above; here are afters:

a11y after arrow after
image image

Conclusion: it's fine in darkly, so maybe this is a theme problem.

image

Will merge once I've completed the playwright tests.

Footnotes

  1. we also don't have light and dark syntax highlighting enabled for inline code, exacerbating this

i simply report
i do not try to explain
but it looks like a11y has a dark mode inline code foreground color
@gordonwoodhull gordonwoodhull marked this pull request as ready for review August 18, 2025 16:45
fixes #8568

this minimal and defensive change (found and iterated with Claude)
changes inline code without .sourceCode to use the same default background
and foreground colors as the block code, when in dark mode.

it is probably more defensive than it needs to be

it also causes code with .sourceCode to default to the code block background
if not otherwise specified, instead of $grey-100, in both modes.
@gordonwoodhull gordonwoodhull merged commit c9be5a1 into main Aug 18, 2025
51 checks passed
@gordonwoodhull gordonwoodhull deleted the bugfix/8568 branch August 18, 2025 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dark mode fixed width font on 1.4.559 has difficult-to-read background color
2 participants